﻿//-----------------------------------------------------------------------
// <copyright file="LocalizableControl.cs" company="INL sprl">
//     Copyright 2009-2010 INL sprl.
// </copyright>
//-----------------------------------------------------------------------

namespace ParseXAML
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Reflection;
    using System.Text;
    using System.Xml.Serialization;

    /// <summary>
    /// Classes qui contient les propriétés à traduire pour un control
    /// </summary>
    [XmlRoot(ElementName = "Properties")]
    public class LocalizableControl
    {
        /// <summary>
        /// Initializes a new instance of the LocalizableControl class.
        /// </summary>
        /// <remarks>
        /// Constructeur nécessaire à cause la sérialization XML
        /// </remarks>
        public LocalizableControl()
        {
        }

        public LocalizableControl(Type control)
        {
            FindLocalizableProperties(control);
        }

        private void FindLocalizableProperties(Type control)
        {
            Properties = new List<string>();
            foreach (PropertyInfo pi in control.GetProperties())
            {
                foreach (object o in pi.GetCustomAttributes(typeof(LocalizableAttribute), false))
                {
                    LocalizableAttribute la = o as LocalizableAttribute;
                    if (la.IsLocalizable)
                    {
                        Properties.Add(pi.Name);
                    }
                }
            }
        }

        /// <summary>
        /// Gets or sets les propriétés à analyser
        /// </summary>
        [XmlElement(ElementName = "Property")]
        public List<string> Properties { get; set; }
    }
}
